{% extends 'macro/base.html' %}

{% block title -%}{{ _("Archives") }} · {{ super() }}{% endblock %}

{% block item %}
  <div class="panel panel-default">
    <div class="panel-heading">
      <i class="fa fa-calendar text-main"></i>
      {{ _("Archives By Datetime") }}
    </div>
    <div class="panel-body">
      {% for date,dates in articles.items() %}
        <ul class="timeline">
          <li class="timeline-count">
            <a data-toggle="collapse" href="#collapse-{{ loop.index }}">{{ date }}</a>
            <span>{{ "（%s篇文章）" | format(dates | length) }}</span>
          </li>
          <div class="collapse {% if loop.index <= 10 %}in{% endif %}" id="collapse-{{ loop.index }}">
            {% set temp = dict(day="0") %}
            {% for article in dates %}
              {% set day = article.created_at.strftime("%d") %}
              <li class="timeline-item">
                <div class="timeline-date{% if temp.day != "0" and temp.day == day and not loop.last %} timeline-date-more{% endif %}" title="{{ article.created_at.strftime("%m月%d日") }}">
                  <span>{{ day }}</span>
                </div>
                <div class="timeline-content">
                  <span class="timeline-text"><a href="{{ url_for('blog.article',pk=article.id) }}">{{ article.title }}</a></span>
                </div>
              </li>
              {% if temp.update(day=day) %}{% endif %}
            {% endfor %}
          </div>
        </ul>
      {% endfor %}
    </div>
  </div>
{% endblock item %}

{% block panel -%}
  <div class="panel panel-default">
    <div class="panel-heading">
      <i class="fa fa-folder-o text-main"></i>
      {{ _('Archives By Category') }}
    </div>
    <div class="panel-body">
      {% for category,count in Archives.categories() %}
        <span class="label label-primary entry-label">
          <a href="{{ url_for('blog.archives',category=category.name) }}">
            {{ category.name }}
            <span class="badge">{{ count }}</span>
          </a>
        </span>
      {% endfor %}
    </div>
  </div>
  <div class="panel panel-default">
    <div class="panel-heading">
      <i class="fa fa-bookmark-o text-main"></i>
      {{ _('Archives By Tags') }}
    </div>
    <div class="panel-body">
      {% for tag,count in Archives.tags() %}
        {% if loop.index == 15 %}
          <div class="collapse" id="entry-tag-list">
        {% endif %}
        <span class="label label-primary entry-label">
          <a href="{{ url_for('blog.archives',tag=tag.name) }}">
            {{ tag.name }}
            <span class="badge">{{ count }}</span>
          </a>
        </span>
        {% if loop.index >= 15 and loop.last %}
          </div>
        {% endif %}
      {% endfor %}
    </div>
    <div class="panel-footer entry-collapse" title="{{ _('open') }}">
      <a data-toggle="collapse" href="#entry-tag-list">
        <i class="fa fa-angle-double-down"></i>
      </a>
    </div>
  </div>
{%- endblock panel %}
